<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>KOA2-BLOA</title>
    <link rel="icon" href="http://120.78.75.213:8080/imgs/ulog.jpg">
    <link rel="stylesheet" href="/index.css">
    <script src="/jquery-3.3.1.min.js"></script>
    <!-- <script src="http://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> -->
    <script>
        function fade(txt) {
            $('.message').text(txt);
            $('.message').animate({
                top: 0
            })
            setTimeout(function () {
                $('.message').animate({
                    top: "-100%"
                })
            }, 1000)
        }
        $(function () {
            $('.signout').click(function () {
                $.ajax({
                    url: "/signout",
                    type: "GET",
                    cache: false,
                    dataType: 'json',
                    success: function (msg) {
                        if (msg) {
                            fade('登出成功')
                            setTimeout(function () {
                                location.href = "/posts"
                            }, 1500)
                        }
                    },
                    error: function () {
                        alert('异常');
                    }
                })
            })
        })
    </script>
</head>

<body>
    <header>
        <div class="user_name">
            <% if(session.user){ %>
            HELLO!
            <%= session.user%>
            <% } %>
            <% if(!session.user){ %>
            欢迎注册登录！
            <% } %>
        </div>
        <div class="message">登录成功</div>
        <div class="user_right">
            <% if(session.user) { %>
            <div class="has_user">
                <% if(type == 'all'){ %>
                <a class="active" href="/posts"> 所有的博客</a>
                <% }else{  %>
                <a href="/posts"> 所有的博客</a>
                <% } %>

                <% if(type == 'my'){ %>
                <a class="active" href="/posts?author=<%= session.user %>"> 我的博客</a>
                <% }else{  %>
                <a href="/posts?author=<%= session.user %>"> 我的博客</a>
                <% } %>

                <% if(type == 'create'){ %>
                <a class="active" href="/create"> 来一发博客吧</a>
                <% }else{  %>
                <a href="/create"> 来一发博客吧</a>
                <% } %>
                <span class="signout">注销 &rarr;</span>
            </div>
            <% } %>

            <% if(!session.user) { %>
            <div class="has_user none_user">
                <% if(type == 'all'){ %>
                <a class="active" href="/posts"> 所有的博客</a>
                <% }else{  %>
                <a href="/posts"> 所有的博客</a>
                <% } %>

                <% if(type == 'signup'){ %>
                <a class="active" href="/signup"> 注册</a>
                <% }else{  %>
                <a href="/signup"> 注册</a>
                <% } %>
                <% if(type == 'signin'){ %>
                <a class="active" href="/signin"> &larr; 登录</a>
                <% }else{  %>
                <a href="/signin"> &larr; 登录</a>
                <% } %>
            </div>
            <% } %>
        </div>

    </header>